/*
 * @Author: szx
 * @Date: 2022-03-05 13:44:15
 * @LastEditTime: 2022-03-05 14:14:22
 * @Description:
 * @FilePath: \leetcode\1400-1499\1401\1401.js
 */
/**
 * @param {number} radius
 * @param {number} xCenter
 * @param {number} yCenter
 * @param {number} x1
 * @param {number} y1
 * @param {number} x2
 * @param {number} y2
 * @return {boolean}
 */
 var checkOverlap = function (radius, xCenter, yCenter, x1, y1, x2, y2) {
    // 在矩形中间
    if (xCenter >= x1 && xCenter <= x2 && yCenter <= y2 && yCenter >= y1) return true;
    // 在上下左右
    if (xCenter >= x1 && xCenter <= x2 && yCenter > y2) return yCenter - y2 <= radius;
    if (xCenter >= x1 && xCenter <= x2 && yCenter < y1) return y1 - yCenter <= radius;
    if (yCenter <= y2 && yCenter >= y1 && xCenter < x1) return  x1- xCenter <= radius;
    if (yCenter <= y2 && yCenter >= y1 && xCenter > x2) return xCenter - x2 <= radius;
    // 在四个角落
    const x0 = Math.floor((x1 + x2) / 2),
        y0 = Math.floor((y1 + y2) / 2);
    const p = [Math.abs(xCenter - x0), Math.abs(yCenter - y0)];
    const q = [x2 - x0, y2 - y0];
    const u = [p[0] - q[0], p[1] - q[1]];
    return u[0] ** 2 + u[1] ** 2 <= radius ** 2;
};
